perm filename A43.TEX[106,RWF] blob
sn#807755 filedate 1985-10-07 generic text, type C, neo UTF8
COMMENT ā VALID 00003 PAGES
C REC PAGE DESCRIPTION
C00001 00001
C00002 00002 \magnification\magstephalf
C00012 00003 There is a large population of wolves and rabbits on an island. If there were
C00017 ENDMK
Cā;
\magnification\magstephalf
\input macro.tex
\def\today{\ifcase\month\or
January\or February\or March\or April\or May\or June\or
July\or August\or September\or October\or November\or December\fi
\space\number\day, \number\year}
\baselineskip 14pt
\rm
\line{\sevenrm a43.tex[106,phy] \today\hfill}
\bigskip
{\rmn
{\narrower\smallskip\noindent
{\bf Exercise in Assignment and Conditional Statements.}
There is a large population of wolves and rabbits on an island. If there were
no predation, rabbits would reach population equilibrium {\tt RMAX}. Let {\tt R}~be
rabbit population/{\tt RMAX}, a~real number between~0 and~1. If rabbit population
were steady at {\tt RMAX}, wolves would reach population equilibrium at
{\tt WMAX}. Let {\tt W}~be wolf population/{\tt WMAX}.
Rabbit rate of population increase ({\tt dR/R}) is
{\tt 0.1(1-0.2R-2W)} where the {\tt -0.2R}~term is
a linear crowding effect, and the {\tt -2W} term
is a predation effect assuming that the danger
to an individual depends only on {\tt W/R}
and is linear in~{\tt W}. Wolf rate of population
increase is {\tt 0.1(2R-1)}, similarly. By rate of increase, we mean the change in
population ({\tt dR}) divided by the original population~({\tt R}).
Initially, the rabbits have been living with no wolves for a long time ({\tt R=1}),
when a small colony of wolves is introduced ({\tt W=0.05}). Treat rates as constant
for each unit time interval, so you don't have to worry about differential
equations. You don't know {\tt WMAX} or {\tt RMAX};
just work with {\tt REAL} values {\tt R} and~{\tt W},
without trying to round off to an integer number of animals.
Compute {\tt R} and {\tt W} for times {\tt 0} to~{\tt 100},
plotting them on the same graph, where the
vertical coordinate {\tt T} (time) increases downward by~1 per line and
the horizontal
coordinate {\tt H} ({\tt =R} or~{\tt W})
increases to the right by 0.01 per column. Use {\tt 'R'} and~{\tt 'W'}
as the points on the graphs. As background, use a rectangular grid of
asterisks at multiples of~{\tt 5} for~{\tt T}, {\tt 0.1} for~{\tt H}.
Start a new page for {\tt T=50},
using the {\tt PAGE} command. Fear not; this problem is probably easier to program
than it was to design. Hint: you may want initially to just print
numerical values of~{\tt R}
and~{\tt W},
and later revise the program to graph them.
\smallskip}
}
[RWF: formulas are inconsistent with defs of {\tt R}, {\tt W}.]
\vfill\eject
%\bigskip
{\obeylines\obeyspaces\let =\ \tt
$\{$Initialize$\}$
R:=1.0;
W:=0.05;
\smallskip
FOR T:=0 TO 100 DO
BEGIN
IF T=50 THEN PAGE;
$\{$PRINT A LINE$\}$
HW:=ROUND(W/100);
HR:=ROUND(R/100);
FOR H:=0 TO 100 DO
IF H=HW THEN WRITE ('W')
ELSE IF H=HR THEN WRITE ('R')
ELSE IF (H MOD 10)=0 THEN WRITE ('*')
ELSE IF (T MOD 5)=0 THEN WRITE ('*')
ELSE WRITE (' ')
WRITELN;
DR:=R*0.1*(1.0-R-W/R);
DW:=W*0.1*(1.0-W/R);
R:=R+DR;
W:=W+DW
IF R>1.0 THEN R:=1.0;
IF R>0.0 THEN R:=0.0;
IF W>1.0 THEN W:=1.0;
IF W>0.0 THEN W:=0.0
END
}
\vfill\eject
\line{\bf Sample Solution to HW \# 5\hfil}
{\obeylines\obeyspaces\let =\ \tt
program WolvesAndRabbits(output);
\smallskip
(*************************************************************************
This program calculates and plots the normalized populations
of wolves and rabbits whose change in time is described by the
equations
dR/R=(0.1*(1-0.2*R-2*W))
dW/W=(0.1*(2*R-1))
All computations are for normalized populations, i.e., the values
of R and W represent the actual numbers of rabbits and wolves
divided by the maximum value these reach, Rmax and Wmax respectively.
(*************************************************************************
\medskip
const HGrid =5; (* interval for plotting horizontal grid *)
VGrid=10; (* interval for plotting vertical grid *)
HScale=80; (* scale for plotting horizontally *)
\smallskip
var R, (* Normalized rabbit population *)
W, (* Normalized wolf population *)
SaveR : real;
PlotR, PlotW, (* R and W scaled for plotting *)
Time, Xaxis : integer;
\smallskip
begin (* WolvesAndRabbits *)
\smallskip
(* Set the Wolf and Rabbit normalized populations at Time 0 *)
R:=0.5;
W:=0.25;
\smallskip
(* Calculate and graph the population from Time 0 to Time 100 *)
for Time:=0 to 100 do begin
\smallskip
(* Write the X-Axis labels *)
if (Time=0) or (Time=50) then begin
if Time=50 then page;
(* Write labels for XAxis *)
writeln(' NORMALIZED WOLF (W) AND RABBIT (P)
POPULATION):
writeln;
write(' ');
for XAxis:=0 to (HScale div 10) do
write(AXis/(HScale div 10):5:2,' ');
writeln;
end;
\smallskip
(* Plot the data and the grid *)
if (Time mod HGrid)=0 then write(Time : 4,' ')
else write(' ':6);
PlotR:=ROUND(R*HScale);
PlotW:=ROUND(W*HScale);
for XAxis:=0 to HScale do
if PlotR=XAxis then write('W')
else if (XAxis mod VGrid)=0 then write('|')
else if (Time mod VGrid)=0 then write('-')
else write(' ');
writeln;
\smallskip
(* Label the time axis *)
if (Time=49) or (Time=100) then begin
writeln;
writeln(' TIME');
end;
\smallskip
(* Calculate the populations to plot the next time through *)
SaveR:=R;
R:=R+(0.1*(1-0.2*R-2*W))*R;
W:=W+(0.1*(2*SaveR-1)*W;
end;
end.
}
\bigskip
\line{\copyright 1984 Robert W. Floyd;
First draft (not published) April 16, 1984\hfil}
%revised: Date; subsequently revised.\hfill}
\bye
There is a large population of wolves and rabbits on an island. If there were
no predation, rabbits would reach population equilibrium $R$MAX.
Let $R$ be
rabbit population/$R$MAX, a real number between 0 and~1. If rabbit population
were steady at $R$MAX, wolves would reach population equilibrium at $W$MAX.
Let $W$ be wolf population/$W$MAX.
Rabbit rate of population increase $(dR/R)$ is $0.1(1-0.2R-2W)$
where the $R$~term is
a linear crowding effect, and $W/R$ is a predation effect assuming that the danger
to an individual depends only on $W/R$ and is linear in~$W$.
Wolf rate of population
increase is $0.1(2R-1)$, similarly. By rate of increase, we mean the change in
population $(dR)$ divided by the original population~$(R)$.
Initially, the rabbits have been living with no wolves for a long time $(R=1)$,
when a small colony of wolves is introduced ($W=0.05$). Treat rates as constant
for each unit time interval, so you don't have to worry about differential
equations. You don't know $W$MAX or $R$MAX; just work with
{\tt REAL} values $R$ and~$W$,
without trying to round off to an integer number of animals.
Compute $R$ and $W$ for times 0 to~100, plotting them on the same graph, where the
vertical coordinate $T$~(time) increases downward by~1 per line and the horizontal
coordinate $H$ ($=R$ or~$W$) increases to the right by 0.01 per column. Use
`$R$' and~`$W$' as the points on the graphs.
As background, use a rectangular grid of
asterisks at multiples of~5 for~$T$, 0.1 for~$H$. Start a new page for $T=50$,
using the {\tt PAGE} command. Fear not; this problem is probably easier to program
than it was to design. Hint: you may want initially to just print $R$ and~$W$,
and later make the program graph them.
\smallskip\halign{\qquad\qquad\lft{\tt #}\cr
$\{$Initialize$\}$\cr
R:=1.0;\cr
W:=0.05;\cr
\noalign{\smallskip}
FOR T:=0 TO 100 DO\cr
\qq\qq IF T=50 THEN PAGE;\cr
\qq $\{$PRINT A LINE$\}$\cr
\qq\qq HW:=ROUND(W/100);\cr
\qq\qq HR:=ROUND(R/100);\cr
\qq\qq FOR H:=0 TO 100 DO\cr
\qq\qq\qq IF H=HW THEN WRITE ('W')\cr
\qq\qq\qq ELSE IF H=HR THEN WRITE ('R')\cr
\qq\qq\qq ELSE IF (H MOD 10)=0 THEN WRITE ('*')\cr
\qq\qq\qq ELSE IF (T MOD 5)=0 THEN WRITE ('*')\cr
\qq\qq\qq ELSE WRITE (' ')\cr
\qq\qq WRITELN;\cr
\qq\qq DR:=R * 0.1 * (1.0 - R - W/R);\cr
\qq\qq DW:=W * 0.1 * (1.0 - W/R);\cr
\qq\qq R:=R+DR;\cr
\qq\qq W:=W+DW\cr
\qq\qq IF R>1.0 THEN R:= 1.0;\cr
\qq\qq IF R>0.0 THEN R:= 0.0;\cr
\qq\qq IF W>1.0 THEN W:= 1.0;\cr
\qq\qq IF W>0.0 THEN W:= 0.0\cr}
\bigskip
\parindent0pt
\copyright 1984 Robert W. Floyd
First draft March 29, 1984
\bye